//! @file   lc_thread_manager.h
//! @brief  
//! @author Sayan Chaliha
//! @date   September, 2011
//!
//! 
#ifndef _LC_THREAD_MANAGER_H
#define _LC_THREAD_MANAGER_H

#include "libcyan_internal.h"
#include "lc_types.h"
#include "lc_object.h"
#include "lc_linked_list.h"
#include "lc_thread.h"
#include "lc_mutex.h"
#include "lc_condition_variable.h"

namespace cyan {
    class CYAN_API ThreadManager : public Object {
    public:
        static ThreadManager* getInstance();
        static Thread* getContextualThread();
        static Bool isContextualThreadPrimordial();
        
    private:
        CYAN_HIDDEN ThreadManager();
        virtual CYAN_HIDDEN ~ThreadManager();
        
        static void CYAN_HIDDEN registerThread(Thread*);
        static void CYAN_HIDDEN unregisterThread(Thread*);
        static void CYAN_HIDDEN setLocalReference(Thread*);
        
        static ThreadManager CYAN_HIDDEN threadManager_;
        static LinkedList<Thread*>* activeThreads_;
        static Mutex* listMutex_;
        static ConditionVariable* listEmptyCondition_;
        static ThreadStorage<Thread*>* threadLocalRef_;
        
        friend class Thread;
    };
}

#endif /* _LC_THREAD_MANAGER_H */
